package com.four.reimbursemanage.controller;

import com.four.reimbursemanage.common.bean.ResponseData;
import com.four.reimbursemanage.common.controller.BaseController;
import com.four.reimbursemanage.dao.OutmoneyApplyMapper;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.entity.OutmoneyApply;
import com.four.reimbursemanage.service.OutmoneyApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("/outmoneyApply")
public class OutmoneyApplyController extends BaseController {
    @Autowired
    OutmoneyApplyMapper outmoneyApplyMapper;
    @Autowired
    private OutmoneyApplyService outmoneyApplyService;

    /**
     * 查询出差报销申请列表
     */

    @GetMapping("/outmoneyApplyList")
    public ResponseData<Object> getOutmoneyApply(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "memberName",required = false) String memberName,
            @RequestParam(value = "state",required = false) Integer state
    ){

       return returnObject(outmoneyApplyService.getOnrePage(pageNum,pageSize, memberName, state));
    }

    @GetMapping("/selectByNum")
    public ResponseData<Object> getByNum(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "memberName",required = false) String memberName,
            @RequestParam(value = "state",required = false) Integer state,
            @RequestParam(value = "number",required = false) String number
    ){
        return returnObject(outmoneyApplyService.getOnrePageUser(pageNum,pageSize, memberName, state, number));
    }

    /**
     * 新增出差报销申请
     */
    @PostMapping("/add")
    public ResponseData<Boolean> add(@DateTimeFormat(pattern = "yyyy-MM-dd") OutmoneyApply outmoneyApply)
    {
        return returnBoolean(outmoneyApplyService.insertOutmoneyApply(outmoneyApply));
    }

    /**
     * 修改日常报销申请
     */

    @PutMapping("/update")
    public ResponseData<Boolean> edit(@RequestBody OutmoneyApply outmoneyApply)
    {
        return returnBoolean(outmoneyApplyService.updateOutmoneyApply(outmoneyApply));
    }

    @PutMapping("/updateC")
    public ResponseData<Boolean> updateS(@RequestBody OutmoneyApply outmoneyApply)
    {
        return returnBoolean(outmoneyApplyService.updateC(outmoneyApply));
    }
}
